<template>
    <div>
        <Row type="flex" justify="center" align="middle">
            <Col span="24">
                <Form ref="searchForm" :model="searchData" inline>
                    <Form-item prop="wname">
                        <Input type="text" style="width:150px" v-model="searchData.wname" placeholder="会员姓名">
                        </Input>
                    </Form-item>
                    <Form-item prop="telno">
                        <Input type="text" style="width:150px" v-model="searchData.telno" placeholder="电话号码">
                        </Input>
                    </Form-item>
                    <Form-item prop="worktype">
                        <Input type="text" style="width:150px" v-model="searchData.worktype" placeholder="工种">
                        </Input>
                    </Form-item>
                    <Form-item prop="isactive">
                         <Select v-model="searchData.userstyle" style="width:100px" placeholder="类型">
                           <Option value="">全部</Option>
                            <Option value="1">{{ $t('userstyle_1') }}</Option>
                            <Option value="2">{{ $t('userstyle_2') }}</Option>
                        </Select>
                    </Form-item>
                    <Form-item prop="isactive">
                         <Select v-model="searchData.isactive" style="width:100px" placeholder="状态">
                           <Option value="">全部</Option>
                            <Option value="0">{{ $t('isactive_0') }}</Option>
                            <Option value="1">{{ $t('isactive_1') }}</Option>
                        </Select>
                    </Form-item>
                     <Form-item prop="ispass">
                         <Select v-model="searchData.ispass" style="width:100px" placeholder="审核状态">
                            <Option value="">全部</Option>
                            <Option value="0">{{ $t('ispass_0') }}</Option>
                            <Option value="1">{{ $t('ispass_1') }}</Option>
                            <Option value="2">{{ $t('ispass_2') }}</Option>
                        </Select>
                    </Form-item>
                    <Form-item prop="releaseUser">
                          <Date-picker v-model="searchData.createdate" format="yyyy-MM-dd HH:mm:ss" type="datetimerange" placement="bottom-end"
                          placeholder="选择日期" style="width: 400px" @on-change="createdateChange"></Date-picker>
                      </Form-item>
                    <Form-item>
                        <Button type="primary" @click="search" :loading="loading">
                           <span v-if="!loading">搜索</span>
                           <span v-else>加载中</span>
                        </Button>
                    </Form-item>
                </Form>
                <br>
                <Button type="primary" @click="passsuccess">批量审核通过</Button> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <Button type="warning" @click="passfail">批量审核失败</Button>
            </Col>
            <Col span="24">
                <Table :columns="column" :data="list"  @on-selection-change="setpasslistchange"></Table>
                <Page :total="pagedata.total" size="small" :current="pagedata.current" :page-size="pagedata.pageSize" :page-size-opts="pagedata.pageSizeOpts"
                    @on-change="pageChange" @on-page-size-change="sizeChange"
                show-elevator show-sizer show-total></Page>
            </Col>
        </Row>
         <Modal v-model="showinfoModel" title="找活信息" width="1000">
            <Row>
              <Col span="24">
                <Card>
                  <p slot="title">
                    用户信息
                  </p>
                    <Row>
                      <Col span="12">
                        <p>姓名：{{info.wname}}</p>
                      </Col>
                      <Col span="12">
                        <p>电话：{{info.telno}}</p>
                      </Col>
                    </Row>
                </Card>
              </Col>
              <Col span="24">
                <Card>
                  <p slot="title">
                    招工信息
                  </p>
                  <div slot="extra" >
                      <Button type="info" @click="updateInfo">信息按钮</Button>
                  </div>
                    <Row>
                      <Col span="8">
                        <p>类型：{{$t('userstyle_' + info.userstyle)}}</p>
                        <p>工种：{{info.worktype}}</p>
                      </Col>
                      <Col span="8">
                        <p>审核状态：{{$t('ispass_' + info.ispass)}}</p>
                        <p>创建时间：{{info.createdate}}</p>
                      </Col>
                       <Col span="8">
                        <p>会员状态：{{$t('isactive_' + info.isactive)}}</p>
                        <p>关闭时间：{{info.unactivetime}}</p>
                      </Col>
                      <Col span="24">
                        <p>地址:{{info.city}}{{info.disc}}{{info.address}}</p>
                      </Col>
                      <Col span="24">
                        <p>简要描述:{{info.disstr}}</p>
                      </Col>
                      <Col span="24">
                        <p>详细:{{info.info}}</p>
                      </Col>
                    </Row>
                </Card>
              </Col>
              <Col span="24" v-if="isupdateData">
                <Card>
                  <p slot="title">
                      信息修改
                  </p>
                  <div slot="extra" >
                    <Button type="info" @click="saveUpdateInfo">保存</Button>&nbsp;&nbsp;
                    <Button type="text" @click="isupdateData=!isupdateData">取消</Button>
                  </div>
                  <div>
                    <Form :model="updateData" >
                      <Form-item label="详细">
                        <Input v-model="updateData.info" type="textarea" :rows="4" placeholder="请输入"></Input>
                      </Form-item>
                    </Form>
                  </div>
                </Card>
              </Col>
            </Row>
        </Modal>
    </div>
</template>
<script>
import { getjobhuntinglist, updatejobhuntingispassbyid, updateinfoforadmin } from '@/api/work'
export default {
  name: 'jobhuntinglist',
  data () {
    var self = this
    return {
      loading: false,
      isupdateData: false,
      showinfoModel: false,
      info: {},
      wuid: this.$store.state.user.userId,
      list: [],
      column: [
        {
          type: 'selection',
          width: 50,
          align: 'center'
        },
        {
          title: 'ID',
          key: 'id',
          width: 80
        },
        {
          title: '会员姓名',
          key: 'wname'
        },
        {
          title: '手机号',
          key: 'telno'
        },
        {
          title: '日工资',
          key: 'daysalary',
          sortable: true
        },
        {
          title: '工种',
          key: 'worktype',
          width: 80
        },
        {
          title: '类型',
          key: 'userstyle',
          width: 100,
          render: function (h, params) {
            const usestr = self.$t('userstyle_' + params.row.userstyle)
            var div = h('div', {}, usestr)
            return div
          }
        },
        {
          title: '状态',
          key: 'isactive',
          width: 100,
          render: function (h, params) {
            const usestr = self.$t('isactive_' + params.row.isactive)
            var div = h('div', {}, usestr)
            return div
          }
        },
        {
          title: '审核状态',
          key: 'ispass',
          width: 100,
          render: function (h, params) {
            const usestr = self.$t('ispass_' + params.row.ispass)
            var div = h('div', {}, usestr)
            return div
          }
        },
        {
          title: '创建时间',
          key: 'createdate'
        },
        {
          title: '审核时间',
          key: 'passtime'
        },
        {
          title: '关闭时间',
          key: 'unactivetime'
        },
        {
          title: '操作',
          key: 'option',
          align: 'left',
          width: 200,
          render: function (h, params) {
            var btn1 = h('Button', {
              props: {
                type: 'text',
                size: 'small'
              },
              on: {
                click: (data) => {
                  self.showinfoModel = true
                  self.info = params.row
                }
              }
            }, '查看')
            var btns = []
            btns.push(btn1)
            if (params.row.isactive === 1) {
            }
            return btns
          }
        }
      ],
      searchData: {
        telno: '',
        wname: '',
        isactive: '',
        ispass: '',
        userstyle: '',
        worktype: '',
        createdate: []
      },
      pagedata: {
        total: 10,
        current: 1,
        pageSize: 10,
        pageSizeOpts: [10, 50, 100]
      },
      passlist: [],
      updateData: {
        id: 0,
        info: ''
      }
    }
  },
  methods: {
    search () {
      this.pagedata.current = 1
      this.getList()
    },
    getList () {
      this.loading = true
      this.searchData.page = this.pagedata.current
      this.searchData.size = this.pagedata.pageSize
      getjobhuntinglist(this.searchData).then(res => {
        const data = res.data
        if (data.code !== 200) {
          this.$Message.error(data.msg)
          this.list = []
          this.pagedata.total = 0
          this.pagedata.current = 1
        } else {
          const usedata = data.data
          this.pagedata.total = usedata.count
          this.list = usedata.list
        }
        this.loading = false
      })
    },
    pageChange (current) {
      this.pagedata.current = current
      this.getList()
    },
    sizeChange (pageSize) {
      this.pagedata.pageSize = pageSize
      this.pagedata.current = 1
      this.getList()
    },
    passsuccess () {
      if (this.passlist.length <= 0) {
        this.$Message.error('无提交数据')
        return false
      }
      const idlist = this.passlist
      const ispass = 1
      const wuid = this.wuid
      updatejobhuntingispassbyid({ idlist, ispass, wuid }).then(res => {
        const data = res.data
        if (data.code !== 200) {
          this.$Message.error(data.msg)
        } else {
          this.getList()
        }
      })
    },
    passfail  () {
      if (this.passlist.length <= 0) {
        this.$Message.error('无提交数据')
        return false
      }
      const idlist = this.passlist
      const ispass = 2
      const wuid = this.wuid
      updatejobhuntingispassbyid({ idlist, ispass, wuid }).then(res => {
        const data = res.data
        if (data.code !== 200) {
          this.$Message.error(data.msg)
        } else {
          this.getList()
        }
      })
    },
    setpasslistchange (selection) {
      if (selection.length >= 0) {
        this.passlist = []
      }
      for (var j = 0, len = selection.length; j < len; j++) {
        this.passlist.push(selection[j].id)
      }
      console.log(this.passlist)
    },
    updateInfo () {
      this.isupdateData = true
      this.updateData.id = this.info.id
      this.updateData.info = this.info.info
    },
    saveUpdateInfo () {
      updateinfoforadmin(this.updateData).then(res => {
        const data = res.data
        if (data.code !== 200) {
          this.$Message.error(data.msg)
        } else {
          this.isupdateData = false
          this.showinfoModel = false
          this.getList()
        }
      })
    },
    createdateChange (values) {
      this.searchData.createdate = values
    }
  },
  mounted () {
    this.getList()
  }
}
</script>
